package com.dzxcqmxm.servlet.album;

import com.dzxcqmxm.Dao.AlbumDao;
import com.dzxcqmxm.Dao.impl.AlbumDaoImpl;
import com.dzxcqmxm.JB.Album;
import com.dzxcqmxm.Dao.impl.testDel.deleteAllFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Payboi
 * @create 2022/6/4-21:35
 * @FileName delAlbumServlet
 * @Description
 */
@WebServlet("/delAlbumServlet")
public class delAlbumServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /**
         * 这是删除数据库数据
         * 而且不能只删除相册表的数据库
         * 如果图片表也有相册表存在的路径也要删掉
         *
         * 弄个多表删除即可
         *
         */
        AlbumDao albumDao = new AlbumDaoImpl();
        Album album = new Album();
        try {
            //获得表单数据
            album.setAlbumName(new String(request.getParameter("AlbumName" ).getBytes("iso-8859-1"),"UTF-8"));

            try {
                albumDao.delAlbum(album.getAlbumName());
            } catch (Exception e) {
                e.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        /**
         * 把本机文件夹也删掉,得获取路径
         * 这是yhContent页面过来的
         */
        String XTXCName = (String) request.getSession ().getAttribute ("XTXCName");
        String dir = "D:/电子相册/"+XTXCName+"/"+album.getAlbumName();
        deleteAllFile.deleteAllFile(dir);

        response.sendRedirect("/dzxc/YongHu/yhContent.jsp");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
